<script type="text/javascript">
    ;(function ($) {
        $.fn.nc_slider = function (options) {
            var defaults = {
                animate: 400,
                timeout: 5000,
                pagination: true,
                pagination_class: 'full-screen-slides-pagination'
            };
            var settings = $.extend({}, defaults, options);

            function nc_slider($slider) {
                var slider = {
                    timer: null,
                    $items: null,
                    items_count: null,
                    max_index: null,
                    $pagination: null,
                    auto: true,
                    current: 0
                };

                function init() {
                    slider.$items = $slider.children();
                    slider.items_count = slider.$items.length;
                    if (slider.items_count <= 1) {
                        return;
                    }
                    slider.max_index = slider.items_count - 1;
                    slider.$items.hide();

                    //初始化导航
                    if (settings.pagination) {
                        //生成导航按钮
                        var pagination_html = '<ul class="' + settings.pagination_class + '">';
                        for (var i = 1; i <= slider.items_count; i++) {
                            pagination_html += '<li>' + '<a href="javascript:;">' + i + '</a>' + '</li>';
                        }
                        pagination_html += '</ul>';
                        $slider.after(pagination_html);

                        slider.$pagination = $slider.next('ul').find('li');

                        //导航按钮单击切换
                        slider.$pagination.on('click', function () {
                            var next = $(this).index();
                            go(next);
                        });

                        //鼠标移动到导航按钮上暂停自动播放
                        slider.$pagination.mouseenter(function () {
                            slider.auto = false;
                        });
                        slider.$pagination.mouseleave(function () {
                            slider.auto = true;
                        });
                    }

                    next();
                }

                function go(next) {
                    slider.$items.eq(slider.current).fadeOut(settings.animate);
                    slider.$items.eq(next).fadeIn(settings.animate);
                    slider.current = next;

                    if (settings.pagination) {
                        slider.$pagination.eq(next).addClass('current').siblings('li').removeClass('current');
                    }
                }

                function next() {
                    if (slider.auto) {
                        if (slider.current >= slider.max_index || slider.timer === null) {
                            go(0);
                        } else {
                            go(slider.current + 1);
                        }
                    }
                    slider.timer = setTimeout(next, settings.timeout);
                }

                init();
            }

            return this.each(function () {
                nc_slider($(this));
            });
        };
    })(jQuery);
</script>
<script type="text/javascript">
    //图片延迟加载
    (function ($) {
        $.fn.nc_lazyload_init = function () {
            this.each(function () {
                $(this).after($(this).val().replace(/src=/gi, 'data-src='));
            }).remove();
        };
    })(jQuery);

    //图片延迟加载
    (function ($) {
        $.fn.nc_lazyload = function () {
            var lazy_items = [];
            this.each(function () {
                if ($(this).attr("data-src") !== undefined) {
                    var lazy_item = {
                        object: $(this),
                        url: $(this).attr("data-src")
                    };
                    lazy_items.push(lazy_item);
                }
            });

            var load_img = function () {
                var window_height = $(window).height();
                var scroll_top = $(window).scrollTop();

                $.each(lazy_items, function (i, lazy_item) {
                    if (lazy_item.object) {
                        item_top = lazy_item.object.offset().top - scroll_top;
                        if (item_top >= 0 && item_top < window_height) {
                            if (lazy_item.url) {
                                lazy_item.object.attr("src", lazy_item.url);
                            }
                            lazy_item.object = null;
                        }
                    }
                });
            };
            load_img();
            $(window).bind("scroll", load_img);
        };
    })(jQuery);
</script>
<div id="store_decoration_area" class="store-decoration-page">
<textarea class="lazyload_container" rows="10" cols="30" style="display:none;">
    <?php if(!empty($output['block_list']) && is_array($output['block_list'])) {?>
    <?php foreach($output['block_list'] as $block) {?>
    <?php require('store_decoration_block.php');?>
    <?php } ?>
    <?php } ?>
</textarea>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        //图片延迟加载
        $(".lazyload_container").nc_lazyload_init();
        $("img").nc_lazyload();

        //幻灯片
        $('[nctype="store_decoration_slide"]').nc_slider();
    });
</script>